package cn.tedu.controller;

import cn.tedu.feign.ItemClient;
import cn.tedu.feign.UserClient;
import cn.tedu.pojo.Item;
import cn.tedu.pojo.Order;
import cn.tedu.pojo.User;
import cn.tedu.service.OrderService;
import cn.tedu.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;

@RestController
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
        return JsonResult.ok(order);
    }


    @GetMapping("/")
    public JsonResult<Order> addOrder(){
        Order order = new Order();
        order.setId("sfsdfser33w");
        order.setUser(new User(7,null,null));
        order.setItems(Arrays.asList(new Item[]{
                new Item(1,"aaa",2),
                new Item(2,"aaa",2),
                new Item(3,"aaa",2),
                new Item(4,"aaa",1),
                new Item(5,"aaa",5)
        }));
        orderService.addOrder(order);

        return JsonResult.ok().msg("保存订单成功");
    }

}
